package com.binguo.model.mybatis;

/**
 * 标准公用查询参数
 *
 */
public class StdDomain {
    public static final Integer DEFAULT_OFFSET = 1;
    public static final Integer DEFAULT_LIMIT = 20;

    private Integer offset;
    private Integer limit;
    private String start;
    private String end;
    private String orderBy;

    /**
     * 默认page=1 size=20
     */
    public StdDomain() {
        this.offset = DEFAULT_OFFSET;
        this.limit = DEFAULT_LIMIT;
    }

    public StdDomain page(Integer page) {
        setOffset((page - 1) * limit);
        return this;
    }

    public void disablePaging() {
        setOffset(null);
    }

    public StdDomain size(Integer size) {
        setLimit(size);
        return this;
    }

    public String getStart() {
        return start;
    }

    public void setStart(String start) {
        this.start = start;
    }

    public StdDomain start(String start) {
        setStart(start);
        return this;
    }

    public String getEnd() {
        return end;
    }

    public void setEnd(String end) {
        this.end = end;
    }

    public StdDomain end(String end) {
        setEnd(end);
        return this;
    }

    public Integer getOffset() {
        return offset;
    }

    public void setOffset(Integer offset) {
        this.offset = offset;
    }

    public Integer getLimit() {
        return limit;
    }

    public void setLimit(Integer limit) {
        this.limit = limit;
    }

    public void setPage(Integer page) {
        this.offset = page;
    }

    public void setSize(Integer limit) {
        this.limit = limit;
    }

    public Integer startOffset() {
        return (offset - 1) * limit;
    }

	public String getOrderBy() {
		return orderBy;
	}

	public void setOrderBy(String orderBy) {
		this.orderBy = orderBy;
	}

    @Override
    public String toString() {
        return "StdDomain{" +
                "offset=" + offset +
                ", limit=" + limit +
                ", start='" + start + '\'' +
                ", end='" + end + '\'' +
                ", orderBy='" + orderBy + '\'' +
                '}';
    }
}
